package com.lvmama.pangolin.lmm.service.impl;


import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.PageHelper;
import com.lvmama.pangolin.entity.LMMCareProductVO;
import com.lvmama.pangolin.entity.lmm.LMMCareProduct;
import com.lvmama.pangolin.lmm.service.LMMCareProductService;
import com.lvmama.pangolin.mybatis.mapper.lmm.LMMCareProductMapper;

@Transactional
@Service
public class LMMCareProductServiceImpl implements LMMCareProductService
{
	@Autowired
	private LMMCareProductMapper careProductMapper;
	
	@Override
	public int deleteByPrimaryKey(String productId)
	{
		return careProductMapper.deleteByPrimaryKey(productId);
	}

	@Override
	public int insert(LMMCareProduct record)
	{
		return careProductMapper.insert(record);
	}

	@Override
	public int insertSelective(LMMCareProduct record)
	{
		return careProductMapper.insertSelective(record);
	}

	@Override
	public LMMCareProduct selectByPrimaryKey(String productId)
	{
		return careProductMapper.selectByPrimaryKey(productId);
	}

	@Override
	public List<LMMCareProduct> selectByCond(LMMCareProduct record)
	{
		return careProductMapper.selectByCond(record);
	}

	@Override
	public int updateByPrimaryKeySelective(LMMCareProduct record)
	{
		return careProductMapper.updateByPrimaryKeySelective(record);
	}

	@Override
	public int updateByPrimaryKey(LMMCareProduct record)
	{
		return careProductMapper.updateByPrimaryKey(record);
	}

	@Override
	public int updateDealFlag(LMMCareProduct record)
	{
		return careProductMapper.updateDealFlag(record);
	}

	@Override
	public List<LMMCareProduct> getAllList(LMMCareProductVO pc) {
		PageHelper.startPage(pc.getPage(), pc.getPageSize());
		List<LMMCareProduct> list=careProductMapper.getAllList(pc);
		return list;
	}

	@Override
	public List<LMMCareProduct> getAllCare(LMMCareProductVO pc) {
		PageHelper.startPage(pc.getPage(), pc.getPageSize());
		return careProductMapper.getAllCare(pc);
	}

	@Override
	public List<LMMCareProduct> queryProductbyTime(Map<String ,Object> param)
	{
		return careProductMapper.queryProductbyTime(param);
	}
	
	@Override
	public void delAndInsert(List<LMMCareProduct> list)
	{
		if(list != null && !list.isEmpty())
		{
			for (LMMCareProduct lmmCareProduct : list)
			{
				deleteByPrimaryKey(lmmCareProduct.getProductId());
				insertSelective(lmmCareProduct);
			}
		}
		
	}

	@Override
	public int deleteByProdRange(Map<String, Object> param)
	{
		return careProductMapper.deleteByProdRange(param);
	}
	
	@Override
	public void synCareProduct(List<LMMCareProduct> list,Map<String, Object> param)
	{
		if(list != null && !list.isEmpty())
		{
			careProductMapper.deleteByProdRange(param);
			for (LMMCareProduct lmmCareProduct : list)
			{
				careProductMapper.deleteByPrimaryKey(lmmCareProduct.getProductId());
				careProductMapper.insertSelective(lmmCareProduct);
			}
		}
		
	}

	@Override
	public List<LMMCareProduct> queryProductbyProd(Map<String, Object> param)
	{
		return careProductMapper.queryProductbyProd(param);
	}

	@Override
	public int  deleteByProdUnRange(Map<String, Object> param)
	{
		return careProductMapper.deleteByProdUnRange(param);
	}

	@Override
	public List<LMMCareProduct> getAll(String productId, String productName, String cityName, String businessCode) {
		return careProductMapper.getAll(productId, productName, cityName, businessCode);
	}
	

}
